Conditions | 1 |
Paths | 24 |
Total Lines | 186 |
Code Lines | 130 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | function detectmob() { |
||
314 | $(document).ready(function () { |
||
315 | $('.add_recapcha').on('click', function () { |
||
316 | var s = $("<script></script>"); |
||
317 | s.attr('src', 'https://www.google.com/recaptcha/api.js?hl='+locale); |
||
318 | s.prop('async', true); |
||
319 | s.prop('defer', true); |
||
320 | $("body").append(s); |
||
321 | }); |
||
322 | |||
323 | $('#share-ref__facebook').on('click', function () { |
||
324 | popupwindow('http://www.facebook.com/sharer/sharer.php?u='+$('#ref-input').val(), 'facebook', 500, 350); |
||
325 | }); |
||
326 | |||
327 | $('.mask-phone-input--js').bind('input', function() { |
||
328 | $(this).val(function(_, v){ |
||
329 | return v.replace(/[-\s\(\)]+/g, ''); |
||
330 | }); |
||
331 | }).on('focus', function () { |
||
332 | if ($(this).val() === '') { |
||
333 | $(this).val('+380'); |
||
334 | } |
||
335 | }).on('focusout', function () { |
||
336 | if ($(this).val() === '+380') { |
||
337 | $(this).val(''); |
||
338 | } |
||
339 | }); |
||
340 | |||
341 | $.validator.methods.email = function( value, element ) { |
||
342 | return this.optional( element ) || /^\w([\-\.]{0,1}\w)*\@\w+([\-\.]{0,1}\w)*\.\w{2,4}$/.test( value ); |
||
343 | }; |
||
344 | |||
345 | $('#payment').validate({ |
||
346 | debug: false, |
||
347 | errorClass: "text-error", |
||
348 | errorElement: "p", |
||
349 | onkeyup: false, |
||
350 | highlight: function(element) { |
||
351 | $(element).addClass('input--error'); |
||
352 | }, |
||
353 | unhighlight: function(element) { |
||
354 | $(element).removeClass('input--error'); |
||
355 | } |
||
356 | }); |
||
357 | |||
358 | $.validator.addClassRules({ |
||
359 | 'valid-name': { |
||
360 | required: true, |
||
361 | pattern: /^[A-Za-zА-Яа-яЁёІіЇїЄє\-\s']+$/, |
||
362 | minlength: 2, |
||
363 | maxlength: 32, |
||
364 | }, |
||
365 | 'valid-plainPassword' : { |
||
366 | required: true, |
||
367 | minlength: 2, |
||
368 | maxlength: 72, |
||
369 | }, |
||
370 | 'valid-email' : { |
||
371 | required: true, |
||
372 | email: true, |
||
373 | }, |
||
374 | 'valid-phone' : { |
||
375 | required: false, |
||
376 | minlength: 12, |
||
377 | maxlength: 16, |
||
378 | pattern: /\+[1-9]{1}[0-9]{10,14}$/i, |
||
379 | } |
||
380 | }); |
||
381 | |||
382 | $('#user_promo_code').rules("add", { |
||
383 | minlength: 2, |
||
384 | messages: { |
||
385 | minlength: $.validator.format(Messages[locale].CORRECT_MIN), |
||
386 | required: Messages[locale].FIELD_REQUIRED, |
||
387 | } |
||
388 | }); |
||
389 | |||
390 | $('.open-speaker-popup').on('click', function () { |
||
391 | var speakerElement = $('.speaker-card__top[data-speaker='+$(this).data('speaker')+']'), |
||
392 | e_slug = speakerElement.data('event'), |
||
393 | s_slug = speakerElement.data('speaker'), |
||
394 | with_review = speakerElement.data('review'); |
||
395 | setSpeakerHtml(e_slug, s_slug, with_review); |
||
396 | }); |
||
397 | |||
398 | $('.speaker-card__top').on('click', function () { |
||
399 | var e_slug = $(this).data('event'); |
||
400 | var s_slug = $(this).data('speaker'); |
||
401 | var with_review = $(this).data('review'); |
||
402 | setSpeakerHtml(e_slug, s_slug, with_review); |
||
403 | }); |
||
404 | |||
405 | $('.set-modal-header').on('click', function () { |
||
406 | var e_slug = $(this).data('event'); |
||
407 | var h_type = ''; |
||
408 | if ($(this).hasClass('get-payment')) { |
||
409 | h_type = 'buy'; |
||
410 | } else { |
||
411 | h_type = 'reg'; |
||
412 | } |
||
413 | setModalHeader(e_slug, h_type); |
||
414 | }); |
||
415 | |||
416 | $('.get-payment').on('click', function () { |
||
417 | var elem = $(this); |
||
418 | var e_slug = elem.data('event'); |
||
419 | var promocode = Cookies.get('promocode'); |
||
420 | var promoevent = Cookies.get('promoevent'); |
||
421 | if (detectmob()) { |
||
422 | var queryParams = ''; |
||
423 | if (promocode && promoevent === e_slug) { |
||
424 | queryParams = '?promocode='+promocode; |
||
425 | } |
||
426 | window.location.pathname = homePath + "static-payment/" + e_slug + queryParams; |
||
427 | } else { |
||
428 | setModalHeader(e_slug, 'buy'); |
||
429 | setPaymentHtml(e_slug); |
||
430 | } |
||
431 | }); |
||
432 | |||
433 | $('.add-promo-code-btn').on('click', function () { |
||
434 | if ($('#user_promo_code').valid()) { |
||
435 | var e_slug = $('#pay-form').data('event'); |
||
436 | $.post(Routing.generate('add_promo_code', {code: $("input[name='user_promo_code']").val(), eventSlug: e_slug}), |
||
437 | function (data) { |
||
438 | if (data.result) { |
||
439 | setPaymentHtmlbyData(data, e_slug); |
||
440 | } else { |
||
441 | var validator = $('#payment').validate(); |
||
442 | var errors = { user_promo_code: data.error }; |
||
443 | validator.showErrors(errors); |
||
444 | } |
||
445 | }); |
||
446 | } |
||
447 | }); |
||
448 | |||
449 | $('.add-user-btn').on('click', function () { |
||
450 | if ($('#payment_user_name').valid() && |
||
451 | $('#payment_user_surname').valid() && |
||
452 | $('#payment_user_email').valid()) { |
||
453 | var e_slug = $('#pay-form').data('event'); |
||
454 | $.post(Routing.generate('add_participant_to_payment', |
||
455 | { |
||
456 | eventSlug: e_slug, |
||
457 | name: $("input[name='user-name']").val(), |
||
458 | surname: $("input[name='user-surname']").val(), |
||
459 | email: $("input[name='user-email']").val() |
||
460 | }), |
||
461 | function (data) { |
||
462 | if (data.result) { |
||
463 | setPaymentHtmlbyData(data, e_slug); |
||
464 | } else { |
||
465 | var validator = $('#payment').validate(); |
||
466 | var errors = { "user-email": data.error }; |
||
467 | validator.showErrors(errors); |
||
468 | } |
||
469 | }); |
||
470 | } |
||
471 | }); |
||
472 | |||
473 | $('#buy-ticket-btn').on('click', function () { |
||
474 | var use_phone = $('#user_phone').val(); |
||
475 | if (use_phone !== '' && $('#user_phone').valid()) { |
||
476 | $.post(Routing.generate('update_user_phone', {phoneNumber: use_phone}), function (data) { |
||
477 | }); |
||
478 | } |
||
479 | }); |
||
480 | |||
481 | $(document).on('click', '.like-btn-js', function (e) { |
||
482 | e.preventDefault(); |
||
483 | var rv_slug = $(this).data('review'); |
||
484 | $.post(Routing.generate('like_review', {reviewSlug: rv_slug}), |
||
485 | function (data) { |
||
486 | if (data.result) { |
||
487 | $("div[data-review='"+ rv_slug+"']").html('<i class="icon-like like-btn__icon"></i>'+data.likesCount); |
||
488 | } else { |
||
489 | $("div[data-review='"+rv_slug+"']").html('<i class="icon-like like-btn__icon"></i>error'); |
||
490 | } |
||
491 | }); |
||
492 | }); |
||
493 | |||
494 | $('iframe').each(function() { |
||
495 | if ($(this).data('src')) { |
||
496 | $(this).attr('src', $(this).data('src')); |
||
497 | } |
||
498 | }); |
||
499 | }); |
||
500 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.